package org.ucas.kgraph.utils.constants;

import org.springframework.http.HttpStatus;

/**
 * 整理的错误类型
 * @author suemi
 */
public class ErrCode {

  public static ErrCode BAD_REQUEST = new ErrCode(400, 0, "bad request");
  public static ErrCode ROOT_DEFECT = new ErrCode(400, 1, "operation need select root");

  
  public static ErrCode DEFINITION_DEFECT = new ErrCode(400, 1, "operation need term definition!");
  public static ErrCode PERM_DEFECT = new ErrCode(400, 1, "operation need perm_list");
  public static ErrCode File_LevelMuch = new ErrCode(400, 1, "the level of file should less than 5");
  
  public static ErrCode STATE_ERROR = new ErrCode(400, 5, "state error");
  public static ErrCode UNAUTHORIZED = new ErrCode(401, 0, "unauthorized");
  public static ErrCode FORBIDDEN = new ErrCode(403, 0, "permission denied");
  public static ErrCode DISABLED_ACCOUNT = new ErrCode(402, 1, "disabled account");
  public static ErrCode WRONG_TOKEN = new ErrCode(403, 1, "unmatched username and password!");
  
  public static ErrCode INVALID_ROOTID = new ErrCode(403, 2, "term should have a valid rootId");
  public static ErrCode DIFFERENT_ROOTID = new ErrCode(403, 3, "relation should under same root term!");
  public static ErrCode WRONG_CODE = new ErrCode(403,0,"unmatched code!");
  public static ErrCode WRONG_COM = new ErrCode(404,0,"com no exist!");
  public static ErrCode USER_NOTEXISTS = new ErrCode(404, 1, "user not exsist");
  public static ErrCode TERM_NOTEXISTS = new ErrCode(404, 2, "term not exsist");
  public static ErrCode RELATION_NOTEXISTS = new ErrCode(404, 3, "relation not exsist");
  public static ErrCode USER_CONFLICT = new ErrCode(409,0,"User already exists,check your name!");
  public static ErrCode COM_CONFLICT = new ErrCode(405,0,"Company already exists,check your name!");
  public static ErrCode TERM_CONFLICT = new ErrCode(409, 1, "term definition is already used");
  public static ErrCode RELATION_CONFLICT = new ErrCode(409, 1, "this relation already exists!");
  public static ErrCode ROLE_CONFLICT = new ErrCode(409, 1, "this role already exists!");

  public static ErrCode UNKNOWN = new ErrCode(503,0,"unknown error, wait a minute to retry!");


  public final HttpStatus status;

  public final int subCode;

  public final String message;

  public ErrCode(int status, int subCode, String message) {
    this(HttpStatus.valueOf(status), subCode, message);
  }

  public ErrCode(HttpStatus status, int subCode, String message) {
    this.status = status;
    this.subCode = subCode;
    this.message = message;
  }

  public ErrCode(HttpStatus status, int subCode) {
    this(status, subCode, null);
  }

  public ErrCode(HttpStatus status, String message) {
    this(status, 0, message);
  }

  public int getErrorCode() {
    return subCode;
  }

  public HttpStatus getStatus() {
    return status;
  }

  public String getMessage() {
    return message;
  }
}
